package 数组.middle;

import java.util.*;

/**
 * LWZ TODO : 2020/8/16
 *
 */

/**
 * @author Lw中
 * @date 2020/8/16 14:12
 */
public class JiuWuLing {

    public static int[] deckRevealedIncreasing(int[] deck) {
        int N = deck.length;
        Deque<Integer> index = new LinkedList();
        for (int i = 0; i < N; ++i) {
            index.add(i);
        }

        int[] ans = new int[N];
        Arrays.sort(deck);
        for (int card: deck) {
            ans[index.pollFirst()] = card;
            if (!index.isEmpty()) {
                // 将队列头部的元素取出存放在队列尾部
                index.add(index.pollFirst());
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] arr = {17,13,11,2,3,5,7};
        int[] ints = deckRevealedIncreasing(arr);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

}
